<hr class="layui-bg-gray" id="tempSyncLayId">
<hr class="layui-bg-gray" id="tempConfigTreeData">

<div style="width: 100%;">

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend>【函数】同步操作 (建议: 数据库1对1配置同步!)</legend>
    </fieldset>

    <hr class="layui-bg-gray">
    <hr class="layui-bg-gray">

    <table style="width: 100%;" id="sea-tab">
        <tr style="width: 100%;height: 60px">
            <td style="text-align: right;width: 100px"><b>选择配置：</b></td>
            <td style="text-align: left;width: 100px">
                <input name="eConfigId" id="eConfigId1" type="hidden" />
                <input type="text" name="eConfigName" id="eConfigName1" lay-filter="tree" placeholder="请选择配置"  autocomplete="off" class="layui-input">
            </td>
            <td style="text-align: right;width: 150px"><b>选择要同步的函数：</b></td>
            <td style="text-align: left;width: 100px">
                <input type="text" name="dFunName" id="dFunName1" lay-filter="tree" placeholder="请选择函数"  autocomplete="off" class="layui-input">
            </td>
            <td style="width: 150px; text-align:center">
                <div class="layui-btn-container">
                    <button type="button" id="doFunSync" class="layui-btn layui-btn-lg layui-btn-normal layui-btn-radius">执行同步</button>
                </div>
            </td>
        </tr>
    </table>

</div>

<hr class="layui-bg-gray">
<hr class="layui-bg-gray">


<script>
    // 加载配置列表
    $(function () {

        $.ajax({
            type:'get',
            url:'tableConfig/queryAllConfigVo',
            success:function (res) {
                $('#tempConfigTreeData').data('tempConfigTreeData',res.data);
            }
        })
    });


    $(document.body).on('click', '#eConfigName1', function () {
        // 获取配置列表
        layui.use('layer', function() {
            var $ = layui.jquery, layer = layui.layer;

            var layId = layer.open({
                title:'请选择配置',
                id: 'LAY_configTree',//设定一个id，防止重复弹出
                type: 1,
                area: ['300px', '400px'],
                shadeClose: true,
                closeBtn: 0,
                content: getHtml('/sys/config/tree.html')
            });

            $('#tempSyncLayId').attr('layId',layId);
        });
    });


    $(document.body).on('click', '#dFunName1', function () {
        let cid = $('#eConfigName1').val();
        if (cid == null || cid == ''){
            layer.alert('请先选择配置');
        }else {
            layui.use('layer', function() {
                var $ = layui.jquery, layer = layui.layer;

                layer.open({
                    title:'选择要同步的函数',
                    id: 'LAY_tabCheckTree',//设定一个id，防止重复弹出
                    type: 1,
                    area: ['300px', '400px'],
                    shadeClose: true,
                    closeBtn: 0,
                    btn: ['确定','取消'],
                    content: getHtml('/sys/fun/tree.html'),
                    yes: function(index){
                        layui.use('tree', function() {
                            var tree = layui.tree
                            var checkedData = tree.getChecked('syncCheckFunId'); //获取选中节点的数据
                            let tables = getCheckedTables(checkedData);
                            document.getElementById("dFunName1").value= tables;

                        })

                        layer.close(index);
                    },
                    btn2: function(index){
                        layer.close(index);
                    }
                });

            });

        }

    });


    $(document.body).on('click', '#doFunSync', function () {

        let configId = $('#eConfigId1').val();
        let funName = $('#dFunName1').val();
        let size = $('#dSize1').val();

        $.ajax({
            type:'post',
            url:'mysql/syncFunData',
            data:{'configId':configId,'funName':funName},
            success:function (res) {
                layer.msg(res.desc);
            }
        })
    });

</script>


